<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>订单列表</title>
    <link rel="stylesheet" href="/plugins/element-ui/index.css">
    <style>
        .tableBar {
            display: flex;
            justify-content: space-between;
        }
        .tableBox {
            margin-top: 20px;
            margin-bottom: 20px;
            border-bottom: solid 2px #f3f4f7;
            border-top: solid 2px #f3f4f7;
        }
        .pageList {
            display: flex;
            justify-content: center;
        }
        .non {
            color: red;
        }
    </style>
</head>
<body>
<div class="dashboard-container" id="member-app">
    <div class="container">
        <div class="tableBar">
            <el-input
                    v-model="input"
                    placeholder="请输入订单号"
                    style="width: 250px"
                    clearable
                    @keyup.enter.native="handleQuery">
                <i
                        slot="prefix"
                        class="el-input__icon el-icon-search"
                        style="cursor: pointer"
                        @click="handleQuery">
                </i>
            </el-input>
            <el-select v-model="orderStatus" placeholder="请选择订单状态">
                <el-option label="全部订单" value=""></el-option>
                <el-option label="交易成功" value="4"></el-option>
                <el-option label="待付款" value="1"></el-option>
                <el-option label="待发货" value="2"></el-option>
                <el-option label="待收货" value="3"></el-option>
                <el-option label="交易失败" value="0"></el-option>
            </el-select>
        </div>
        <el-table
                :data="tableData"
                stripe
                size="mini"
                class="tableBox">
            <el-table-column
                    prop="orderId"
                    label="订单号"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="收货人"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="phone"
                    label="手机号"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="address"
                    label="收货地址"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column
                    prop="paymentMoney"
                    label="实付金额"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="created"
                    label="创建时间"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="paymentTime"
                    label="支付时间"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="consignTime"
                    label="发货时间"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="endTime"
                    label="完成时间"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="shippingCode"
                    label="物流单号"
                    align="center"
                    :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="订单状态"
                    align="center">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.status === 0" type="danger" disable-transitions>交易失败</el-tag>
                    <el-tag v-if="scope.row.status === 1" type="warning" disable-transitions>待付款</el-tag>
                    <el-tag v-if="scope.row.status === 2" type="info" disable-transitions>待发货</el-tag>
                    <el-tag v-if="scope.row.status === 3" disable-transitions>待收货</el-tag>
                    <el-tag v-if="scope.row.status === 4" type="success" disable-transitions>交易成功</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    label="操作"
                    align="center">
                <template slot-scope="scope">
                    <el-button
                            round
                            :disabled="scope.row.status != 2"
                            type="primary"
                            size="small"
                            class="blueBut"
                            @click="editHandle(scope.row.orderId)">
                        发货
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                class="pageList"
                :page-size="pageSize"
                layout="total, prev, pager, next, jumper"
                :total="counts"
                :current-page.sync="page"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange">
        </el-pagination>
    </div>
</div>

<script src="/plugins/vue/vue.js"></script>
<script src="/plugins/element-ui/index.js"></script>
<script src="/plugins/axios/axios-0.18.0.js"></script>
<script src="/js/member.js"></script>
<script>
    new Vue({
        el: '#member-app',
        data() {
            return {
                input: '',
                counts: 0,
                page: 1,
                pageSize: 5,
                tableData : [],
                id: '',
                orderStatus: ''
            }
        },
        watch: {
            orderStatus(newVal) {
                this.page = 1
                this.init()
            }
        },
        methods: {
            init() {
                const params = {
                    pageNum: this.page,
                    pageSize: this.pageSize,
                    status: this.orderStatus,
                    orderId: this.input ? this.input : undefined,
                }
                axios.get('/order/page', {params}).then(res => {
                    let info = res.data
                    if (info.code === 1) {
                        let list = info.data.records
                        this.tableData = list || []
                        this.counts = info.data.total
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            // 查询
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 发货
            editHandle (id) {
                this.$confirm("确认发货？", "提示", {type: "warning"}).then(() => {
                    axios.put('/order', {orderId: id, status: 3, consignTime: new Date()}).then(res => {
                        let info = res.data
                        if (info.code === 1) {
                            this.$message.success('订单状态已修改！')
                            this.init()
                        } else {
                            this.$message.error(res.msg || '操作失败')
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })
                })
            },
            // 删除
            removeHandle(id) {
                this.$confirm("确认删除？", "提示", {type: "warning"}).then(() => {
                    axios.delete('/order/' + id).then(res => {
                        let info = res.data
                        if (info.code === 1) {
                            this.init()
                            this.$message.success('文章删除成功！')
                        } else {
                            this.$message.error('文章删除失败！')
                        }
                    })
                })
            },

            handleSizeChange (val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange (val) {
                this.page = val
                this.init()
            }
        },
        created() {
            this.init()
        },
    })
</script>
</body>
</html>
